package com.comm.util.pages;

import java.util.List;

/**
 * 分页公共类
 * @author Dengxuzhao
 * @time 2016-04-29
 */
public class PageUtils {
private Integer currPage = 1;
	
	private Integer pageSize = 20;
	
	private Integer nextPage = 0;
	
	private Integer backPage = 0;
	
	private Integer maxPage = 0;
	
	private Integer totalRecord = 0;
	
	private Integer startRecord = 0;
	
	private List<Object> retLst;

	public PageUtils() {
		super();
	}
	
	public PageUtils(Integer currPage, Integer pageSize, Integer totalRecord) {
		super();
		this.currPage = currPage;
		this.pageSize = pageSize;
		this.totalRecord = totalRecord;
		this.maxPage = (int)Math.ceil(((float)this.totalRecord) / ((float)this.pageSize)); //设置最大页数
		this.backPage = this.currPage - 1 > 0 ? this.currPage - 1 : 1; //计算上一页页码
		this.nextPage = this.currPage + 1 < this.maxPage ? this.currPage + 1 : this.maxPage; //计算下一页页码
		this.startRecord = (this.currPage - 1) * this.pageSize; //计算开始查询坐标
	}

	public PageUtils(Integer currPage, Integer pageSize, Integer nextPage,
			Integer backPage, Integer maxPage, Integer totalRecord) {
		super();
		this.currPage = currPage;
		this.pageSize = pageSize;
		this.nextPage = nextPage;
		this.backPage = backPage;
		this.maxPage = maxPage;
		this.totalRecord = totalRecord;
	}

	/**
	 * 当前页码
	 * @return
	 */
	public Integer getCurrPage() {
		return currPage;
	}

	public void setCurrPage(Integer currPage) {
		this.currPage = currPage;
	}

	/**
	 * 页容量
	 * @return
	 */
	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * 下一页页码
	 * @return
	 */
	public Integer getNextPage() {
		return nextPage;
	}

	public void setNextPage(Integer nextPage) { 
		this.nextPage = this.currPage + 1 < this.maxPage ? this.currPage + 1 : this.maxPage;
	}

	/**
	 * 上一页页码
	 * @return
	 */
	public Integer getBackPage() {
		return backPage;
	}

	public void setBackPage(Integer backPage) {
		this.backPage = this.currPage - 1 > 0 ? this.currPage - 1 : 1;
	}

	/**
	 * 最大页码
	 * @return
	 */
	public Integer getMaxPage() {
		return maxPage;
	}

	public void setMaxPage(Integer maxPage) {
		this.maxPage = (int)Math.ceil(((float)this.totalRecord) / ((float)this.pageSize));
	}

	/**
	 * 最大记录数
	 * @return
	 */
	public Integer getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(Integer totalRecord) {
		this.totalRecord = totalRecord;
	}

	/**
	 * 查询开始记录数
	 * @return
	 */
	public Integer getStartRecord() {
		return startRecord;
	}

	public void setStartRecord(Integer startRecord) {
		this.startRecord = (this.currPage - 1) * this.pageSize;
	}

	/**
	 * 查询返回对象
	 * @return
	 */
	public List<Object> getRetLst() {
		return retLst;
	}

	public void setRetLst(List<Object> retLst) {
		this.retLst = retLst;
	}
}
